package com.designpattern.MediatorPattern;

/**
 * @Author yue
 * @Date 2021-07-26
 * @Version V1.0.1
 * @Description 同事抽象类
 */

public abstract class Colleague {
    //中介者抽象类
    protected Mediator mediator;

    //接受消息
    public abstract void receive();

    //发送消息
    public abstract void send();

    public void setMediator(Mediator mediator) {
        this.mediator = mediator;
    }

}

/**
 * 具体的同事类1
 */
class ConcreteColleague1 extends Colleague {

    @Override
    public void receive() {
        System.out.println("具体的同事类1");
    }

    @Override
    public void send() {
        System.out.println("同事1发送消息");
        //请中介者转发
        this.mediator.relay(this);
    }
}

/**
 * 具体的同事类2
 */
class ConcreteColleague2 extends Colleague {

    @Override
    public void receive() {
        System.out.println("具体的同事类2");
    }

    @Override
    public void send() {
        System.out.println("同事2发送消息");
        //请中介者转发
        this.mediator.relay(this);
    }
}